import { Component, OnInit, EventEmitter, Input, Output, ElementRef } from '@angular/core';

import { CudTableService } from '../../../public/serve/cud-table/cud-table.service';
import { Service } from '../../../server/server';
import { addDatatype } from '../effect-add/effect-add.component';
import { HintsService } from '../../../public/serve/hints/hints.service';
declare var $: any;

@Component({
  selector: 'app-effect-update',
  templateUrl: './effect-update.component.html',
})
export class EffectUpdateComponent implements OnInit {

  constructor(private server: Service, private cudTableService: CudTableService,private hintsService:HintsService) { }

  ngOnInit() {
    this.createUserId = this.server.getuser();
    //console.log(this.getTabVal)
    this.superiorUpdate = "最上级"
  }

  public createUserId: any;

  @Input() getTabVal: addDatatype;

  @Input() superiorUpdate: any;

  @Input() superiorUpdateId: any;

  @Output()
  updateOutput: EventEmitter<any[]> = new EventEmitter();

  submitEdit() {

    let url = this.server.baseUrl+'user/functions/modify';
    let data: addDatatype = {
      createUserId: this.createUserId,
      functionId: this.getTabVal.functionId || '',
      functionName: this.getTabVal.functionName,
      functionCode: this.getTabVal.functionCode,
      functionEName: this.getTabVal.functionEName,
      description: this.getTabVal.description,
      enable: Number(this.getTabVal.enable),
      functionType: Number(this.getTabVal.functionType),
      pageUrl: this.getTabVal.pageUrl,
    }
    //console.log(data)
    this.cudTableService.postRequest(url, data).then((res: any) => {
      this.hintsService.messages(res.message,res.result_code);
      if (res.result_code = '0000') {
        $('#update').modal('hide');
        //prompt
        this.updateOutput.emit(res.result_code);
        //update
      }
    }).catch()

  }

  public modalLnit() {
    console.log($("#update"))
    $("#update").modal("hide");
    //this.updateOutput.emit();
  }

}
